<template>
	<!-- 一层子目录 存放学生名单 -->
	
	<view>
		<clock-overview :ft="filter_time" :data="overview_data" v-on:filter_change="handle_filter_change"></clock-overview>
		<view class="root-wrapper">
			<individual-card 
				v-for="item in stu_list" 
				v-bind:info="item">
			</individual-card>
			
			<individual-card
				v-for="item in unfinished_list" 
				v-bind:info="item"
				:unfinished="true">
			</individual-card>
		</view>
	</view>
</template>

<script>
	// TODO 设置整个页面的布局 设置页面的title
	import individualCard from '../../components/individual-card.vue'
	import clockOverview from '../../components/clock-overview.vue'
	
	export default {
		components: {
			individualCard,
			clockOverview
		},
		
		mounted() {
			console.log('mounted')
		},
		onLoad: function (option) { 
			console.log('onLoad')
			uni.setNavigationBarTitle({
			    title: option.name
			})
			
			console.log('sub page中的filter_time', option.filter_time); 
			console.log('sub page中的deptId', option.deptId);
			

			this.filter_time = option.filter_time
			this.deptId = option.deptId
			this.title = option.name
		
			// 获取overview数据
			this.$u.api.getDeptSimpleInfo({
				'date': this.filter_time,
				'deptId': this.deptId,
				'userId': 0	
			}).then(res => {
				console.log('simple', res)
				this.overview_data = {
					normal: res.data.clockedNumber - res.data.exceptionNumber,
					abnormal: res.data.exceptionNumber,
					unfinished:res.data.totalNumber - res.data.clockedNumber,
				}
			})
			
			// 获取详细数据
			this.$u.api.getDeptAllInfo({
				'date': this.filter_time,
				'deptId': this.deptId,
				'userId': 0				// this.$store.state.deptId
			}).then(msg => {
				console.log('msg',msg)
				this.stu_list = msg.data
			})
			
			// 获取未打卡详细数据
			this.$u.api.getDeptUnClockedInfo({
				'date': this.filter_time,
				'deptId': this.deptId
			}).then(unchecked => {
				this.unfinished_list = unchecked.data
			})
			
			
		},
		data() {
			return {
				deptId: 0,
				overview_data: {},
				option: {},
				filter_time: '',
				stu_list: [],
				unfinished_list: [],
					// "clockIsAbnormal": false,
					// "clockIsIntimate": false,
					// "clockLocation": "北京市-北京市-东城区",
					// "clockTel": "13018994001",
					// "clockTemp": 37,
					// "clockTime": "2021-06-29 01:50:06",
					// "clockVaccineDose": 1,
					// "clockVaccineTime": "2021-06-10 00:00:00",
					// "id": 21,
					// "name": "陈翊",
					// "statClockState": false,
					// "userId": 4
				title: ''
			}
		},
		methods: {
			handle_filter_change: function(params) {
				console.log('响应了事件', params)
				this.filter_time = params
				
				let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
				let curRoute = routes[routes.length - 1].route
				let dir = curRoute.split('/')
				let cur_page = dir[dir.length - 1]
				
				uni.redirectTo({
				    url: cur_page + '?deptId=' + this.deptId
								  + '&filter_time=' + this.filter_time
								  + '&name=' + this.title
				});
			}
		}
	}
</script>

<style>
	

</style>
